package com.example.wechat

import android.content.BroadcastReceiver
import android.content.ContentValues.TAG
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

   // var broadCast = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

      //  btn_toggle.setOnClickListener{ it as TextView
      //     val running = it.tag as Boolean
      //     if(running){
      //        stopBroadcastReceive(it)
      //     }else{
      //        startBroadcastReceive(it)
      //    }
      //  }
    }
//    private fun startBroadcastReceive(it: TextView) {
//
//        val filter = IntentFilter()
//        val receiver = getReceiver()
//        this.registerReceiver(receiver, filter)
//        it.text="停止广播"
//
//        it.tag = true
//    }
//
//    private fun getReceiver(): BroadcastReceiver {
//
//        return if(mReceiver == null) object : BroadcastReceiver(){
//            override fun onReceive(p0: Context?, p1: Intent?) {
//
//            }
//        }else mReceiver
//
//    }
//    private fun stopBroadcastReceive(it: TextView) {
//
//        val receiver = getReceiver()
//        it.text="停止广播"
//        it.tag = false
//    }

    override fun onStart(){
        super.onStart()
        println("onStart")
        Log.d(TAG,"onDestory")
    }
    override fun onPause(){
        super.onPause()

        println("onPause")
        Log.d(TAG,"onPause")
    }
    override fun onRestart(){
        super.onRestart()
        println("onRestart")
        Log.d(TAG,"onRestart")
    }
    override fun onResume(){
        super.onResume()
        println("onResume")
        Log.d(TAG,"onResume")
    }
    override fun onStop(){
        super.onStop()
        println("onStop")
        Log.d(TAG,"onStop")
    }
    override fun onDestroy(){
        super.onDestroy()
        println("onDestroy")
        Log.d(TAG,"onDestory")
    }

    fun onClick(view: View) {
        Log.d(TAG,"onClick_login")
        when(view.id){
            R.id.login->{
                val intent = Intent(this, HomeActivity::class.java)
                startActivity(intent)
            }
        }
    }

}